package com.thread.plbc;

/**
 * @author げっしょく
 * @date 2021/8/5
 */
public class ThreadDemo5 {
    public static void main(String[] args) {
        //模拟火车站购票处卖100张票
        TicketOffice to = new TicketOffice(100);
        Thread t1 = new ThreadD5exer(to);
        Thread t2 = new ThreadD5exer(to);
        Thread t3 = new ThreadD5exer(to);
        Thread t4 = new ThreadD5exer(to);
        t1.setName("t1");
        t2.setName("t2");
        t3.setName("t3");
        t4.setName("t4");
        t1.start();
        t2.start();
        t3.start();
        t4.start();
    }
}


class ThreadD5exer extends Thread{
    private TicketOffice to;
    public ThreadD5exer(TicketOffice to){
        this.to = to;
    }
    @Override
    public void run() {
        while(this.to.getTicket() > 0){
            this.to.BuyTicket();
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
